package org.ceteca.explica.core.management;
/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.warehouse.ProductOT;
import org.ceteca.explica.core.warehouse.WarehouseOT;

public class DocumentLineOT extends BaseVO implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long idDocumentLine=0;
	private DocumentOT document;
	private ProductOT product;
	private String description;
	private BigDecimal quantity=new BigDecimal(0);
	private BigDecimal price=new BigDecimal(0), costPrice=new BigDecimal(0);
	private BigDecimal discount=new BigDecimal(0);
	private BigDecimal orderQuantity=new BigDecimal(0);
	private BigDecimal vat=new BigDecimal(0);
	private String productReference;
	private int order=0;
	private Integer version=new Integer(0);
	private BigDecimal re=new BigDecimal(0);
	private Set<MovementOT> movements;
	private WarehouseOT warehouse;
	
	
	
	
	public WarehouseOT getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(WarehouseOT warehouse) {
		this.warehouse = warehouse;
	}
	public Set<MovementOT> getMovements() {
		return movements;
	}

	public void setMovements(Set<MovementOT> movements) {
		this.movements = movements;
	}

	public BigDecimal getRe() {
		return re;
	}

	public void setRe(BigDecimal re) {
		this.re = re;
	}

	@Override
	public boolean equals(Long id) {
		return id!=null &&  id==getIdDocumentLine();
	}

	public BigDecimal getCostPrice() {
		return costPrice;
	}

	public String getDescription() {
		return description;
	}

	public BigDecimal getDiscount() {
		return discount;
	}


	
	public DocumentOT getDocument() {
		return document;
	}

	@Override
	public String getEntityId() {
		return InterfaceManagement.EXPLICA_ENTITY_DOCUMENT_LINE_ID;
	}

	public long getIdDocumentLine() {
		return idDocumentLine;
	}

	@Override
	public long getInternalId() {
		return getIdDocumentLine();
	}

	@Override
	public String getInternalValue() {
		return getProductReference()+" "+getDescription();
	}

	public int getOrder() {
		return order;
	}

	public BigDecimal getOrderQuantity() {
		return orderQuantity;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public ProductOT getProduct() {
		return product;
	}

	public String getProductReference() {
		return productReference;
	}

	public BigDecimal getQuantity() {
		return quantity;
	}



	public BigDecimal getVat() {
		return vat;
	}

	public Integer getVersion() {
		return version;
	}

	public void setCostPrice(BigDecimal costPrice) {
		this.costPrice = costPrice;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setDiscount(BigDecimal discount) {
		this.discount = discount;
	}

	public void setDocument(DocumentOT document) {
		this.document = document;
	}

	public void setIdDocumentLine(long idDocumentLine) {
		this.idDocumentLine = idDocumentLine;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public void setOrderQuantity(BigDecimal orderQuantity) {
		this.orderQuantity = orderQuantity;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public void setProduct(ProductOT product) {
		this.product = product;
	}

	public void setProductReference(String productReference) {
		this.productReference = productReference;
	}

	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}



	public void setVat(BigDecimal vat) {
		this.vat = vat;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
	public BigDecimal getGrossAmount(){
		return getQuantity().multiply(getPrice());
	}
	
	public BigDecimal getDiscountAmount(){
		return getGrossAmount().multiply(getDiscount()).divide(new BigDecimal(100));
	}
	
	public BigDecimal getNetAmountBeforeTax(){
		return getGrossAmount().subtract(getDiscountAmount());
	}

	
	

	
	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getDocument());
	        hcb.append(getOrder());
	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final DocumentLineOT other = (DocumentLineOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getDocument(), other.getDocument());
	            eqb.append(getOrder(), other.getOrder());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }

	    @Override
	    public String toString(){
	    	return this.getDescription();
	    }
		public DocumentLineOT() {
			super();
		}


	
}
